package SolrApps;

import UntilSolr.UntilSolrCloud;
import model.Human;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrServer;
import org.apache.solr.common.SolrInputDocument;

import java.io.IOException;

public class AddData {

    public void addDoc(){
        CloudSolrServer cloudSolrServer = UntilSolrCloud.getCollection();
        SolrInputDocument data = new SolrInputDocument();
        data.addField("id", "row999");
        data.addField("name", "kkk");
        data.addField("city", "sx");
        data.addField("salary", "8589494");
        try {
            cloudSolrServer.add(data);
            cloudSolrServer.commit();
            System.out.println("输入doc成功！");
        } catch (SolrServerException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void addBean(){
        CloudSolrServer cloudSolrServer = UntilSolrCloud.getCollection();
        Human data = new Human();
        data.setId("row998");
        data.setName("sad");
        data.setCity("sfas");
        data.setSalary("4512");
        try {
            cloudSolrServer.addBean(data);
            cloudSolrServer.commit();
            System.out.println("输入bean成功！");
        } catch (SolrServerException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args){
        AddData addData = new AddData();
        //addData.addDoc();
        addData.addBean();
    }
}
